import {Router} from "express";
import commonRouters from "@src/routes/common/commonRouters";
import fileUpload from 'express-fileupload';

const commonRouter = Router();
// 图片上传
const uploadRouter = Router();
// 指定文件上传中间件
uploadRouter.use(fileUpload({
  // 自动创建目录
  createParentPath: true,
  // 文件名uri进行解码
  uriDecodeFileNames: true,
  // 防止内存泄露
  useTempFiles: true,
  // 临时文件存放目录
  tempFileDir: "/tmp",
  // 超时
  uploadTimeout: 10000,
}));
// 文件上传处理器
uploadRouter.post(commonRouters.paths.upload, commonRouters.upload);
uploadRouter.get(commonRouters.paths.tem, commonRouters.readFile);


// 通用接口处理器
commonRouter.use("/", uploadRouter);
export default commonRouter;